﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 简单实现一个剪刀石头布游戏
{
    internal class Game
    {
        int cmpCount = 0;
        int plyCount = 0;
        private Image[] images = { Resource1._1, Resource1._2, Resource1._3, Resource1._4, Resource1._5, Resource1._3, Resource1._4, Resource1._5 };
        public Game() { }
        public void Show(PictureBox[] pictureBoxes)
        {
            for(int i = 0; i < pictureBoxes.Length; i++)
            {
                pictureBoxes[i].Image = images[i];
            }
        }
        public void Play(PictureBox pictureBox, int player, Label label1, Label label2)
        {
            Random rnd = new Random();
            int computer = rnd.Next(2, 5);
            Image image = images[computer];
            pictureBox.Image = image;
            //剪刀：2，石头：3，布：4
            if(computer == player)
            {
                MessageBox.Show("平局", "比赛结果");
            }
            else if((computer == 2 && player == 3) || (computer == 3 && player == 4) || (computer == 4 && player == 2))
            {
                MessageBox.Show("玩家胜利", "比赛结果");
                plyCount++;
                label2.Text = Convert.ToString(plyCount);
            }
            else
            {
                MessageBox.Show("电脑胜利", "比赛结果");
                cmpCount++;
                label1.Text = Convert.ToString(cmpCount);
            }
        }
    }
}
